
const Router = require('@koa/router');
const ticketsController = require('../controllers/ticketsController');

const router = new Router({ prefix: '/api/tickets' });

// 获取所有可购买的门票信息
/**
 * @swagger
 * /api/tickets/list:
 *   get:
 *     summary: 获取所有可购买的门票信息
 *     parameters:
 *       - in: query
 *         name: scenic_id
 *         schema:
 *           type: integer
 *         description: 景点 ID
 *       - in: query
 *         name: category
 *         schema:
 *           type: string
 *         description: 票种类别（成人票、儿童票等）
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *         description: 页码（默认 1）
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *         description: 每页条数（默认 10）
 *     responses:
 *       200:
 *         description: 成功获取票务信息
 *       500:
 *         description: 获取失败
 */
router.get('/list', ticketsController.getTicketsList);

// 获取单个票务详情
/**
 * @swagger
 * /api/tickets/{id}:
 *   get:
 *     summary: 获取单个票务详情
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 票务 ID
 *     responses:
 *       200:
 *         description: 成功获取票务详情
 *       500:
 *         description: 获取失败
 */
router.get('/:id', ticketsController.getTicketById);

// 用户购买门票
/**
 * @swagger
 * /api/tickets/order:
 *   post:
 *     summary: 用户购买门票
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: integer
 *               ticket_id:
 *                 type: integer
 *               quantity:
 *                 type: integer
 *               total_price:
 *                 type: number
 *               name:
 *                 type: string
 *               phone:
 *                 type: string
 *               payment_method:
 *                 type: string
 *               order_date:
 *                 type: string
 *     responses:
 *       201:
 *         description: 订单创建成功
 *       500:
 *         description: 创建失败
 */
router.post('/order', ticketsController.createOrder);

// 查询用户订单
/**
 * @swagger
 * /api/tickets/orders/{user_id}:
 *   get:
 *     summary: 查询用户订单
 *     parameters:
 *       - in: path
 *         name: user_id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 用户 ID
 *     responses:
 *       200:
 *         description: 成功获取用户订单
 *       500:
 *         description: 获取失败
 */
router.get('/orders/:user_id', ticketsController.getUserOrders);

// 支付订单
/**
 * @swagger
 * /api/tickets/pay:
 *   post:
 *     summary: 支付订单
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               order_id:
 *                 type: integer
 *               user_id:
 *                 type: integer
 *               payment_method:
 *                 type: string
 *     responses:
 *       200:
 *         description: 支付成功
 *       500:
 *         description: 支付失败
 */
router.post('/pay', ticketsController.payOrder);

// 取消订单
/**
 * @swagger
 * /api/tickets/cancel:
 *   post:
 *     summary: 取消订单
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               order_id:
 *                 type: integer
 *               user_id:
 *                 type: integer
 *     responses:
 *       200:
 *         description: 订单取消成功
 *       500:
 *         description: 取消失败
 */
router.post('/cancel', ticketsController.cancelOrder);

// 退款申请
/**
 * @swagger
 * /api/tickets/refund:
 *   post:
 *     summary: 退款申请
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               order_id:
 *                 type: integer
 *               user_id:
 *                 type: integer
 *               reason:
 *                 type: string
 *     responses:
 *       200:
 *         description: 退款申请成功
 *       500:
 *         description: 退款申请失败
 */
router.post('/refund', ticketsController.refundOrder);

// 更新票务库存
/**
 * @swagger
 * /api/tickets/stock/{id}:
 *   put:
 *     summary: 更新票务库存
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 票务 ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               stock:
 *                 type: integer
 *     responses:
 *       200:
 *         description: 库存更新成功
 *       500:
 *         description: 更新失败
 */
router.put('/stock/:id', ticketsController.updateTicketStock);

module.exports = router;
